package topin.facecat.Android;

import java.util.ArrayList;

import facecat.topin.core.*;

/*
* 绘图命令
 */
public class NativeCmd {
    public String m_cmd = "";

    public ArrayList<FCPoint> points = new ArrayList<FCPoint>();

    public ArrayList<FCPointF> pointfs = new ArrayList<FCPointF>();

    public ArrayList<Long> colors = new ArrayList<Long>();

    public ArrayList<String> texts = new ArrayList<String>();

    public ArrayList<FCRect> rects = new ArrayList<FCRect>();

    public ArrayList<FCRectF> rectfs = new ArrayList<FCRectF>();

    public ArrayList<Double> values = new ArrayList<Double>();

    public static ArrayList<NativeCmd> strToCommand(String str){
        ArrayList<NativeCmd> cmds = new ArrayList<NativeCmd>();
        if(str.length() > 0){
            char[] charArray = str.toCharArray();
            int start = 0, textLength = charArray.length;
            ArrayList<String> strs = new ArrayList<String>();
            for (int i = 0; i < textLength; i++)
            {
                if(charArray[i] == ','){
                    String left = str.substring(start, i);
                    int wordLength = FCTran.strToInt(left);
                    String right = str.substring(i + 1, i + 1 + wordLength);
                    start = i + 1 + wordLength;
                    strs.add(right);
                    i = start - 1;
                }
            }
            int pos = 0;
            int cmdCount = FCTran.strToInt(strs.get(pos));
            pos++;
            for(int i = 0; i < cmdCount; i++){
                NativeCmd nc = new NativeCmd();
                nc.m_cmd = strs.get(pos);
                pos++;
                int pointsSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < pointsSize; j++){
                    int pX = FCTran.strToInt(strs.get(pos));
                    int pY = FCTran.strToInt(strs.get(pos + 1));
                    nc.points.add(new FCPoint(pX,pY));
                    pos += 2;
                }
                int pointfsSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < pointfsSize; j++){
                    float pX = FCTran.strToFloat(strs.get(pos));
                    float pY = FCTran.strToFloat(strs.get(pos + 1));
                    nc.pointfs.add(new FCPointF(pX,pY));
                    pos += 2;
                }
                int colorsSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < colorsSize; j++){
                    Long color = FCTran.strToLong(strs.get(pos));
                    nc.colors.add(color);
                    pos++;
                }
                int textsSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < textsSize; j++){
                    String text = strs.get(pos);
                    nc.texts.add(text);
                    pos++;
                }
                int rectsSize = FCTran.strToInt(strs.get(pos));
                pos += 1;
                for(int j = 0; j < rectsSize; j++){
                    int pLeft = FCTran.strToInt(strs.get(pos));
                    int pTop = FCTran.strToInt(strs.get(pos + 1));
                    int pRight = FCTran.strToInt(strs.get(pos + 2));
                    int pBottom = FCTran.strToInt(strs.get(pos + 3));
                    nc.rects.add(new FCRect(pLeft, pTop, pRight, pBottom));
                    pos += 4;
                }
                int rectfsSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < rectfsSize; j++){
                    float pLeft = FCTran.strToFloat(strs.get(pos));
                    float pTop = FCTran.strToFloat(strs.get(pos + 1));
                    float pRight = FCTran.strToFloat(strs.get(pos + 2));
                    float pBottom = FCTran.strToFloat(strs.get(pos + 3));
                    nc.rectfs.add(new FCRectF(pLeft, pTop, pRight, pBottom));
                    pos += 4;
                }
                int valuesSize = FCTran.strToInt(strs.get(pos));
                pos++;
                for(int j = 0; j < valuesSize; j++){
                    double pValue = FCTran.strToDouble(strs.get(pos));
                    nc.values.add(pValue);
                    pos++;
                }
                cmds.add(nc);
            }
        }
        return cmds;
    }
}
